package com.example.sqlitelogin;

import static com.example.sqlitelogin.tools.CodeCommand.auto;

import android.content.Context;
import android.hardware.ConsumerIrManager;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.sqlitelogin.tools.AirBean;
import com.example.sqlitelogin.tools.CodeCommand;
import com.example.sqlitelogin.tools.CustomWhiteActionBar;

public class Kong2Activity extends AppCompatActivity {

    private Button btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9;
    private TextView temptext;
    private TextView lin1,lin2,lin3;
    private TextView temp,templogo,moshi;
    private int tempnum,vary,wind1,wind2,wind3,switchnum,sleepNum;
    private double time_close;
    private TextView sleep,time_Swicth;

    private ConsumerIrManager IR;
    //判断是否有红外功能
    boolean IRBack;

    private View view;
    private TextView tempShow, airWindDir, windDirAuto, windSpeed, modeShow;
    private ImageView modeCold, modeWatted, modeAuto, modeSupply, modeHeating;
    //开关、度数、模式、自动手动、风向、风量


    private  AirBean airBean = new AirBean(0, 25, 1, 0, 1, 2);





    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //状态栏中的文字颜色和图标颜色，需要android系统6.0以上，而且目前只有一种可以修改（一种是深色，一种是浅色即白色）
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //修改为深色，因为我们把状态栏的背景色修改为主题色白色，默认的文字及图标颜色为白色，导致看不到了。
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        setContentView(R.layout.activity_kong2);

        CustomWhiteActionBar actionBar1 = findViewById(R.id.action_bar_2);
        actionBar1.setStyle("卧室 空调");


        //获取红外控制类

        //获取ConsumerIrManager实例
        IR = (ConsumerIrManager)Kong2Activity.this.getSystemService(CONSUMER_IR_SERVICE);

        //如果sdk版本大于4.4才进行是否有红外的功能（手机的android版本）
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            IRBack = IR.hasIrEmitter();
            if (!IRBack) {
                Log.e("leo","无红外设备");//可进行下一步操作
            } else {
                Log.e("leo","红外设备就绪");//可进行下一步操作
            }
        }


        btn1=findViewById(R.id.btn_switch);
        btn2=findViewById(R.id.btn_switch2);
        btn3=findViewById(R.id.btn_switch3);
        btn4=findViewById(R.id.btn_switch4);
        btn5=findViewById(R.id.btn_switch5);
        btn6=findViewById(R.id.btn_switch6);
        btn7=findViewById(R.id.btn_switch7);
        btn8=findViewById(R.id.btn_switch8);
        btn9=findViewById(R.id.btn_switch9);
        temptext=findViewById(R.id.temp_text);

        lin1=findViewById(R.id.center_kong_text1);
        lin2=findViewById(R.id.center_kong_text2);
        lin3=findViewById(R.id.center_kong_text3);
        temp=findViewById(R.id.temp);
        moshi=findViewById(R.id.moshi);
        templogo=findViewById(R.id.templogo);

        time_Swicth=findViewById(R.id.time_switch);
        sleep=findViewById(R.id.sleep);


        switchnum=0;
        vary=1;
        tempnum=26;
        wind1=1;
        wind2=1;
        wind3=1;
        sleepNum=1;
        time_close=0;





        lin1.getLayoutParams().width = getScreenWidth(this)/3;
        lin2.getLayoutParams().width = getScreenWidth(this)/3;
        lin3.getLayoutParams().width = getScreenWidth(this)/3;

        time_Swicth.getLayoutParams().width = getScreenWidth(this)/2;
        sleep.getLayoutParams().width = getScreenWidth(this)/2;


        btn1.getLayoutParams().width = getScreenWidth(this)/2;
        btn2.getLayoutParams().width = getScreenWidth(this)/2;
        btn3.getLayoutParams().width = getScreenWidth(this)/3;
        btn4.getLayoutParams().width = getScreenWidth(this)/3;
        btn5.getLayoutParams().width = getScreenWidth(this)/3;
        btn6.getLayoutParams().width = getScreenWidth(this)/3;
        temptext.getLayoutParams().width = getScreenWidth(this)/3;
        btn7.getLayoutParams().width = getScreenWidth(this)/3;
        btn8.getLayoutParams().width = getScreenWidth(this)/2;
        btn9.getLayoutParams().width = getScreenWidth(this)/2;

        btn1.getLayoutParams().height = getScreenHeight(this)/8;
        btn2.getLayoutParams().height = getScreenHeight(this)/8;
        btn3.getLayoutParams().height = getScreenHeight(this)/8;
        btn4.getLayoutParams().height = getScreenHeight(this)/8;
        btn5.getLayoutParams().height = getScreenHeight(this)/8;
        btn6.getLayoutParams().height = getScreenHeight(this)/8;
        btn7.getLayoutParams().height = getScreenHeight(this)/8;
        btn8.getLayoutParams().height = getScreenHeight(this)/8;
        btn9.getLayoutParams().height = getScreenHeight(this)/8;

        temp.setVisibility(temp.INVISIBLE);
        templogo.setVisibility(templogo.INVISIBLE);
        moshi.setVisibility(moshi.INVISIBLE);
        lin1.setVisibility(lin1.INVISIBLE);
        lin2.setVisibility(lin2.INVISIBLE);
        lin3.setVisibility(lin3.INVISIBLE);
        time_Swicth.setVisibility(time_Swicth.INVISIBLE);
        sleep.setVisibility(sleep.INVISIBLE);


        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(switchnum==1){
                    temp.setVisibility(temp.INVISIBLE);
                    templogo.setVisibility(templogo.INVISIBLE);
                    lin1.setVisibility(lin1.INVISIBLE);
                    lin2.setVisibility(lin2.INVISIBLE);
                    lin3.setVisibility(lin3.INVISIBLE);
                    moshi.setVisibility(moshi.INVISIBLE);
                    time_Swicth.setVisibility(sleep.INVISIBLE);
                    sleep.setVisibility(sleep.INVISIBLE);
                    time_close=0;
                    switchnum=0;
                    if (IRBack){
                        airBean.setmPower(0);
                        SendMsg(airBean);
                    }
                }else{
                    temp.setVisibility(temp.VISIBLE);
                    templogo.setVisibility(templogo.VISIBLE);
                    lin1.setVisibility(lin1.VISIBLE);
                    lin2.setVisibility(lin2.VISIBLE);
                    lin3.setVisibility(lin3.VISIBLE);
                    moshi.setVisibility(moshi.VISIBLE);
                    time_close=0;
                    switchnum=1;
                    if (IRBack){
                        airBean.setmPower(1);
                        SendMsg(airBean);
                    }
                }

            }
        });

        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (vary){
                    case 1:
                        moshi.setText("制热");
                        vary=2;
                        if (IRBack){
                            airBean.setmMode(3);
                            SendMsg(airBean);
                        }
                        break;
                    case 2:
                        moshi.setText("除湿");
                        vary=3;
                        if (IRBack){
                            airBean.setmPower(2);
                            SendMsg(airBean);
                        }
                        break;
                    case 3:
                        moshi.setText("制冷");
                        vary=1;
                        if (IRBack){
                            airBean.setmPower(1);
                            SendMsg(airBean);
                        }
                        break;
                }
            }
        });

        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (wind1){
                    case 1:
                        lin1.setText("风速 低");
                        wind1=2;
                        if (IRBack){
                            airBean.setmWindCount(1);
                            SendMsg(airBean);
                        }
                        break;
                    case 2:
                        lin1.setText("风速 中");
                        wind1=3;
                        if (IRBack){
                            airBean.setmWindCount(2);
                            SendMsg(airBean);
                        }
                        break;
                    case 3:
                        lin1.setText("风速 高");
                        if (IRBack){
                            airBean.setmWindCount(3);
                            SendMsg(airBean);
                        }
                        wind1=1;
                        break;
                }
            }
        });

        btn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (wind2){
                    case 1:
                        lin2.setText("风向 上");
                        wind2=2;

                        if (IRBack){
                            airBean.setmWindDir(3);
                            SendMsg(airBean);
                        }
                        break;
                    case 2:
                        lin2.setText("风向 中");
                        wind2=3;
                        if (IRBack){
                            airBean.setmWindCount(2);
                            SendMsg(airBean);
                        }
                        break;
                    case 3:
                        lin2.setText("风向 下");
                        wind2=1;
                        if (IRBack){
                            airBean.setmWindCount(1);
                            SendMsg(airBean);
                        }
                        break;
                }
            }
        });

        btn5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (wind3){
                    case 1:
                        lin3.setText("自动风向");
                        wind3=2;
                        if (IRBack){
                            airBean.setmWindCount(0);
                            SendMsg(airBean);
                        }
                        break;
                    case 2:
                        if (IRBack){
                            airBean.setmWindCount(2);
                            SendMsg(airBean);
                        }
                        break;

                }
            }
        });

        btn6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(tempnum<=29){
                    tempnum++;
                    String s1=""+tempnum;
                    temp.setText(s1);
                    if (IRBack){
                        airBean.setmTmp(tempnum);
                        SendMsg(airBean);
                    }
                }
            }
        });
        btn7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(tempnum>=17){
                    tempnum--;
                    String s2=""+tempnum;
                    temp.setText(s2);
                    if (IRBack){
                        airBean.setmTmp(tempnum);
                        SendMsg(airBean);
                    }
                }
            }
        });

        btn8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (switchnum==1){
                    if (time_close==0){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s3=""+time_close+"小时后关";
                        time_Swicth.setText(s3);
                        if (IRBack){
                            SendMsg(airBean);
                        }
                    }else if(time_close==0.5){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s4=""+time_close+"小时后关";
                        time_Swicth.setText(s4);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }else if(time_close==1){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s5=""+time_close+"小时后关";
                        time_Swicth.setText(s5);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }else if(time_close==1.5){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s6=""+time_close+"小时后关";
                        time_Swicth.setText(s6);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }else if(time_close==2.0){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s7=""+time_close+"小时后关";
                        time_Swicth.setText(s7);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }else if(time_close==2.5){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s8=""+time_close+"小时后关";
                        time_Swicth.setText(s8);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }else if(time_close==3){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s9=""+time_close+"小时后关";
                        time_Swicth.setText(s9);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }else if(time_close==3.5){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s10=""+time_close+"小时后关";
                        time_Swicth.setText(s10);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }else if(time_close==4){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s11=""+time_close+"小时后关";
                        time_Swicth.setText(s11);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }
                    else if(time_close==4.5){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s12=""+time_close+"小时后关";
                        time_Swicth.setText(s12);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }
                    else if(time_close==5){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s13=""+time_close+"小时后关";
                        time_Swicth.setText(s13);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }
                    else if(time_close==5.5){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s14=""+time_close+"小时后关";
                        time_Swicth.setText(s14);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }
                    else if(time_close==6){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s15=""+time_close+"小时后关";
                        time_Swicth.setText(s15);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }
                    else if(time_close==6.5){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s16=""+time_close+"小时后关";
                        time_Swicth.setText(s16);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }else if(time_close==7){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s17=""+time_close+"小时后关";
                        time_Swicth.setText(s17);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }
                    else if(time_close==7.5){
                        time_Swicth.setVisibility(time_Swicth.VISIBLE);
                        time_close=time_close+0.5;
                        String s18=""+time_close+"小时后关";
                        time_Swicth.setText(s18);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }else if(time_close==8){
                        time_close=0;
                        time_Swicth.setVisibility(time_Swicth.INVISIBLE);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }
                }
            }
        });

        btn8.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (switchnum==1){
                    if(time_close!=0)
                    {
                        time_close=0;
                        time_Swicth.setVisibility(time_Swicth.INVISIBLE);
                        if (IRBack){
                            airBean.setmTmp(tempnum);
                            SendMsg(airBean);
                        }
                    }
                }
                return true;
            }
        });

        btn9.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(switchnum==1){
                    switch (sleepNum){
                        case 1:
                            sleep.setVisibility(sleep.VISIBLE);
                            sleepNum=2;
                            if (IRBack){
                                airBean.setmTmp(tempnum);
                                SendMsg(airBean);
                            }
                            break;
                        case 2:
                            sleep.setVisibility(sleep.INVISIBLE);
                            sleepNum=1;
                            if (IRBack){
                                airBean.setmTmp(tempnum);
                                SendMsg(airBean);
                            }
                            break;
                    }
                }
            }
        });





    }

    // 获得屏幕的宽度
    public static int getScreenWidth(Context ctx) {
        // 从系统服务中获取窗口管理器
        WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        // 从默认显示器中获取显示参数保存到dm对象中
        wm.getDefaultDisplay().getMetrics(dm);
        return dm.widthPixels; // 返回屏幕的宽度数值
    }

    // 获得屏幕的高度
    public static int getScreenHeight(Context ctx) {
        // 从系统服务中获取窗口管理器
        WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        // 从默认显示器中获取显示参数保存到dm对象中
        wm.getDefaultDisplay().getMetrics(dm);
        return dm.heightPixels; // 返回屏幕的高度数值
    }

    public void SendMsg(AirBean airBean_Event) {
        Log.e("gaoyu", "要发送的信息" + airBean_Event.toString());

        int mPower = airBean_Event.getmPower(); //开关
        int mTmp = airBean_Event.getmTmp();  //温度
        int mMode = airBean_Event.getmMode();  //模式
        int menergy = airBean_Event.getmenergy();  //节能省电/换气
        int mWindDir = airBean_Event.getmWindDir();   //风向
        int mWindCount = airBean_Event.getmWindCount(); //风量


        int tmWindDir = 0;//二进制方向
        //左右扫风风向判断
        if (mWindDir == 2) {
            tmWindDir = 1;
        } else if (mWindDir == 1) {
            tmWindDir = 0;
        } else {
            tmWindDir = 0;
        }
        //根据所选模式确定检验码
        //校验码 = [(模式 – 1) + (温度 – 16) + 5 +左右扫风+换气+节能]取二进制后四位，再逆序
        //以下为了思路清晰 就不写在一起了
        int check = (mMode - 1) + (mTmp - 16) + 5 + tmWindDir + menergy + menergy;//十进制数字
        String two_chack = Integer.toBinaryString(check);//转换成二进制
        //如果大于四位进行裁剪
        //补零
        switch (two_chack.length()){
            case 3:
                two_chack = "0"+two_chack;
                break;
            case 2:
                two_chack = "00"+two_chack;
                break;
            case 1:
                two_chack = "000"+two_chack;
                break;
        }
        two_chack = two_chack.substring(two_chack.length() - 4, two_chack.length());//取后四位
        String Cut = new StringBuffer(two_chack).reverse().toString();//倒序
        Log.e("gaoyu", "裁剪之前" + two_chack + "裁剪倒序之后" + Cut);

        //分解字符（承载最后四个逆序字符）
        char[] item = new char[5];
        for (int i = 0; i < Cut.length(); i++) {
            item[i] = Cut.charAt(i);
        }
        //操作大数组
        int base[] = CodeCommand.base;

        //第一步 替换校验码  （分七步）
        //取出数组里的四个数
        int one = Integer.valueOf(String.valueOf(item[0])).intValue();
        int two = Integer.valueOf(String.valueOf(item[1])).intValue();
        int three = Integer.valueOf(String.valueOf(item[2])).intValue();
        int four = Integer.valueOf(String.valueOf(item[3])).intValue();
        //64-67位为校验码 131、132 \ 133、134 \ 135、136 \ 137、138
        //第一个数
        if (one == 1) {
            Log.e("gaoyu", "第一个数是1");
            //将大数组里的130、131位置1
            base[130] = CodeCommand.check_d;
            base[131] = CodeCommand.check_u;

        } else {
            Log.e("gaoyu", "第一个数是0");
            //将大数组里的64位不用变
        }
        //第二个数
        if (two == 1) {
            Log.e("gaoyu", "第二个数是1");
            //将大数组里的132、133位置1
            base[132] = CodeCommand.check_d;
            base[133] = CodeCommand.check_u;

        } else {
            Log.e("gaoyu", "第二个数是0");
            //将大数组里的132、133位不用变
        }
        //第三个数
        if (three == 1) {
            Log.e("gaoyu", "第三个数是1");
            //将大数组里的134、135位置1
            base[134] = CodeCommand.check_d;
            base[135] = CodeCommand.check_u;

        } else {
            Log.e("gaoyu", "第三个数是0");
            //将大数组里的134、135位不用变
        }
        //第四个数
        if (four == 1) {
            Log.e("gaoyu", "第四个数是1");
            //将大数组里的136、137位置1
            base[136] = CodeCommand.check_d;
            base[137] = CodeCommand.check_u;
        } else {
            Log.e("gaoyu", "第四个数是0");
            //将大数组里的136、137位不用变
        }

        //第二步 开关  8/9
        if (mPower == 1) {
            Log.e("gaoyu", "开");
            base[8] = CodeCommand.onedown;
            base[9] = CodeCommand.oneup;
        } else {
            base[8] = CodeCommand.zerodown;
            base[9] = CodeCommand.zeroup;
            Log.e("gaoyu", "关");
        }

        //第三步 温度 16-30度   数组中18、25
        switch (mTmp) {
            case 16:
                //默认十六
                break;
            case 17:
                base[18] = CodeCommand.onedown;
                base[19] = CodeCommand.oneup;
                base[20] = CodeCommand.zerodown;
                base[21] = CodeCommand.zeroup;
                base[22] = CodeCommand.zerodown;
                base[23] = CodeCommand.zeroup;
                base[24] = CodeCommand.zerodown;
                base[25] = CodeCommand.zeroup;
                break;
            case 18:
                base[18] = CodeCommand.zerodown;
                base[19] = CodeCommand.zeroup;
                base[20] = CodeCommand.onedown;
                base[21] = CodeCommand.oneup;
                base[22] = CodeCommand.zerodown;
                base[23] = CodeCommand.zeroup;
                base[24] = CodeCommand.zerodown;
                base[25] = CodeCommand.zeroup;
                break;
            case 19:
                base[18] = CodeCommand.onedown;
                base[19] = CodeCommand.oneup;
                base[20] = CodeCommand.onedown;
                base[21] = CodeCommand.oneup;
                base[22] = CodeCommand.zerodown;
                base[23] = CodeCommand.zeroup;
                base[24] = CodeCommand.zerodown;
                base[25] = CodeCommand.zeroup;
                break;
            case 20:
                base[18] = CodeCommand.zerodown;
                base[19] = CodeCommand.zeroup;
                base[20] = CodeCommand.zerodown;
                base[21] = CodeCommand.zeroup;
                base[22] = CodeCommand.onedown;
                base[23] = CodeCommand.oneup;
                base[24] = CodeCommand.zerodown;
                base[25] = CodeCommand.zeroup;
                break;
            case 21:
                base[18] = CodeCommand.onedown;
                base[19] = CodeCommand.oneup;
                base[20] = CodeCommand.zerodown;
                base[21] = CodeCommand.zeroup;
                base[22] = CodeCommand.onedown;
                base[23] = CodeCommand.oneup;
                base[24] = CodeCommand.zerodown;
                base[25] = CodeCommand.zeroup;
                break;
            case 22:
                base[18] = CodeCommand.zerodown;
                base[19] = CodeCommand.zeroup;
                base[20] = CodeCommand.onedown;
                base[21] = CodeCommand.oneup;
                base[22] = CodeCommand.onedown;
                base[23] = CodeCommand.oneup;
                base[24] = CodeCommand.zerodown;
                base[25] = CodeCommand.zeroup;
                break;
            case 23:
                base[18] = CodeCommand.onedown;
                base[19] = CodeCommand.oneup;
                base[20] = CodeCommand.onedown;
                base[21] = CodeCommand.oneup;
                base[22] = CodeCommand.onedown;
                base[23] = CodeCommand.oneup;
                base[24] = CodeCommand.zerodown;
                base[25] = CodeCommand.zeroup;
                break;
            case 24:
                base[18] = CodeCommand.zerodown;
                base[19] = CodeCommand.zeroup;
                base[20] = CodeCommand.zerodown;
                base[21] = CodeCommand.zeroup;
                base[22] = CodeCommand.zerodown;
                base[23] = CodeCommand.zeroup;
                base[24] = CodeCommand.onedown;
                base[25] = CodeCommand.oneup;
                break;
            case 25:
                base[18] = CodeCommand.onedown;
                base[19] = CodeCommand.oneup;
                base[20] = CodeCommand.zerodown;
                base[21] = CodeCommand.zeroup;
                base[22] = CodeCommand.zerodown;
                base[23] = CodeCommand.zeroup;
                base[24] = CodeCommand.onedown;
                base[25] = CodeCommand.oneup;
                break;
            case 26:
                base[18] = CodeCommand.zerodown;
                base[19] = CodeCommand.zeroup;
                base[20] = CodeCommand.onedown;
                base[21] = CodeCommand.oneup;
                base[22] = CodeCommand.zerodown;
                base[23] = CodeCommand.zeroup;
                base[24] = CodeCommand.onedown;
                base[25] = CodeCommand.oneup;
                break;
            case 27:
                base[18] = CodeCommand.onedown;
                base[19] = CodeCommand.oneup;
                base[20] = CodeCommand.onedown;
                base[21] = CodeCommand.oneup;
                base[22] = CodeCommand.zerodown;
                base[23] = CodeCommand.zeroup;
                base[24] = CodeCommand.onedown;
                base[25] = CodeCommand.oneup;
                break;
            case 28:
                base[18] = CodeCommand.zerodown;
                base[19] = CodeCommand.zeroup;
                base[20] = CodeCommand.zerodown;
                base[21] = CodeCommand.zeroup;
                base[22] = CodeCommand.onedown;
                base[23] = CodeCommand.oneup;
                base[24] = CodeCommand.onedown;
                base[25] = CodeCommand.oneup;
                break;
            case 29:
                base[18] = CodeCommand.onedown;
                base[19] = CodeCommand.oneup;
                base[20] = CodeCommand.zerodown;
                base[21] = CodeCommand.zeroup;
                base[22] = CodeCommand.onedown;
                base[23] = CodeCommand.oneup;
                base[24] = CodeCommand.onedown;
                base[25] = CodeCommand.oneup;
                break;
            case 30:
                base[18] = CodeCommand.zerodown;
                base[19] = CodeCommand.zeroup;
                base[20] = CodeCommand.onedown;
                base[21] = CodeCommand.oneup;
                base[22] = CodeCommand.onedown;
                base[23] = CodeCommand.oneup;
                base[24] = CodeCommand.onedown;
                base[25] = CodeCommand.oneup;
                break;
            default:
                break;
        }

        //第四步  模式  2-7
        switch (mMode) {
            case 0:
                base[2] = CodeCommand.zerodown;
                base[3] = CodeCommand.zeroup;
                base[4] = CodeCommand.zerodown;
                base[5] = CodeCommand.zeroup;
                base[6] = CodeCommand.zerodown;
                base[7] = CodeCommand.zeroup;
                break;
            case 1:
                base[2] = CodeCommand.onedown;
                base[3] = CodeCommand.oneup;
                base[4] = CodeCommand.zerodown;
                base[5] = CodeCommand.zeroup;
                base[6] = CodeCommand.zerodown;
                base[7] = CodeCommand.zeroup;
                break;
            case 2:
                base[2] = CodeCommand.zerodown;
                base[3] = CodeCommand.zeroup;
                base[4] = CodeCommand.onedown;
                base[5] = CodeCommand.oneup;
                base[6] = CodeCommand.zerodown;
                base[7] = CodeCommand.zeroup;
                break;
            case 3:
                base[2] = CodeCommand.onedown;
                base[3] = CodeCommand.oneup;
                base[4] = CodeCommand.onedown;
                base[5] = CodeCommand.oneup;
                base[6] = CodeCommand.zerodown;
                base[7] = CodeCommand.zeroup;
                break;
            case 4:
                base[2] = CodeCommand.zerodown;
                base[3] = CodeCommand.zeroup;
                base[4] = CodeCommand.zerodown;
                base[5] = CodeCommand.zeroup;
                base[6] = CodeCommand.onedown;
                base[7] = CodeCommand.oneup;
                break;
        }
        //第五步 节电、换气 48-51
        if (menergy == 1) {
            Log.e("gaoyu", "开启节电换气");
            base[48] = CodeCommand.onedown;
            base[49] = CodeCommand.oneup;
            base[50] = CodeCommand.onedown;
            base[51] = CodeCommand.oneup;
        }else{
            base[48] = CodeCommand.zerodown;
            base[49] = CodeCommand.zeroup;
            base[50] = CodeCommand.zerodown;
            base[51] = CodeCommand.zeroup;
        }
        //第六步  风向  1、上下 36 数组 74.75   2、左右 40  80.81
        switch (mWindDir) {
            case 0:
                //默认
                break;
            case 1:
                base[74] = CodeCommand.onedown;
                base[75] = CodeCommand.oneup;
                break;
            case 2:
                base[80] = CodeCommand.onedown;
                base[81] = CodeCommand.oneup;
                break;
        }

        //第七步  风量  10-13
        switch (mWindCount) {
            case 0:
                //默认
                break;
            case 1:
                base[10] = CodeCommand.onedown;
                base[11] = CodeCommand.oneup;
                base[12] = CodeCommand.zerodown;
                base[13] = CodeCommand.zeroup;
                break;
            case 2:
                base[10] = CodeCommand.zerodown;
                base[11] = CodeCommand.zeroup;
                base[12] = CodeCommand.onedown;
                base[13] = CodeCommand.oneup;
                break;
            case 3:
                base[10] = CodeCommand.onedown;
                base[11] = CodeCommand.oneup;
                base[12] = CodeCommand.onedown;
                base[13] = CodeCommand.oneup;
                break;
        }

        //最后一步 调取红外进行发送
        String content = null;
        for (int i = 0; i < base.length; i++) {
            content += String.valueOf(base[i]) + ",";
        }
        Log.e("gaoyu", "数组信息是" + content);
        //发送完数据将大数组还原

        sendIrMsg(38000,base);
        base = CodeCommand.base;

    }
    private void sendIrMsg(int carrierFrequency, int[] pattern) {
        IR.transmit(carrierFrequency, pattern);
    }
}